/********************************************************************

Defines some common exceptions.

Write Date: 2011/03/23
Author: Deng Nianchen
>>>> The file contains following classes:
>>>> OutOfRangeException

Modify Date: 2011/06/02
Author: Deng Nianchen
>>>> Add classes:
>>>> AllocateMemoryFailException
>>>> NotOOPObjectException

Modify Date: 2011/07/16
Author: Deng Nianchen
>>>> Add classes:
>>>> TypeConvertFailException

*********************************************************************/
#ifndef COMMON_EXCEPTIONS_HPP
#define COMMON_EXCEPTIONS_HPP
#include "OOPException.hpp"

_OOPUTILS_BEGIN

/**************************************************************************************************
 * <summary>  Exception for signalling out of range errors.  </summary>
 *
 * <remarks>  Deng Nianchen, 2011/3/23. </remarks>
 **************************************************************************************************/

class OutOfRangeException : public OOPException
{

public:

  virtual OOPString getReason ()
  {
    return L"The index is out of range";
  }

};

/**************************************************************************************************
 * <summary>  Exception for signalling the failure of allocating memory.  </summary>
 *
 * <remarks>  Deng Nianchen, 2011/3/23. </remarks>
 **************************************************************************************************/

class AllocateMemoryFailException : public OOPException
{

public:

  virtual OOPString getReason () const throw ()
  {
    return L"Fail to allocate memory";
  }

};

/**************************************************************************************************
 * <summary>  Exception for signalling when an object is not
 * 						an OOPObject (or its descendant) instance.  </summary>
 *
 * <remarks>  Deng Nianchen, 2011/3/23. </remarks>
 **************************************************************************************************/

class NotOOPObjectException : public OOPException
{

public:

  virtual OOPString getReson () const throw ()
  {
    return L"The object is not an OOPObject (or its descendant) instance";
  }

};

/**************************************************************************************************
 * <summary>  Exception for signalling type convert errors.  </summary>
 *
 * <remarks>  Deng Nianchen, 2011/6/2. </remarks>
 **************************************************************************************************/

class TypeConvertFailException : public OOPException
{
private:

    OOPString _srcTypeStr;
    OOPString _destTypeStr;

public:

    TypeConvertFailException (const char * srcTypeStr,
            const char * destTypeStr)
            : _srcTypeStr (OOPString::fromStdString (srcTypeStr)),
			_destTypeStr (OOPString::fromStdString (destTypeStr)) {}

    virtual OOPString getReson () const throw ()
    {
        return OOPString::fromStdString ("Cannot convert from ") + _srcTypeStr
                + L" to " + _destTypeStr;
    }

};

_OOPUTILS_END

#endif